// 仓库数据
const defaultState = {
    count: 1,
    yangjun:{name:'另一个redux数据'}
}
//   在reducer纯函数中的第二个参数为action，
// action可以获取到dispatch操作的类型和数据
const reducer = (state = defaultState, action) => {
    // reducer 不允许直接修改 state的数据
    if (action.type === 'addCount') {
        const newState = {
            ...state,
            count: state.count + action.value
        }
        return newState
    }

    if (action.type === 'subCount') {
        const newState = {
            ...state,
            count: state.count - action.value
        }
        return newState
    }
    if (action.type === 'gaoYixia') {
        const newGao = {
            ...state,
            yangjun: action.data
        }
        return newGao
    }
    return state
}


export default reducer